package cn.hesion.leetcode;
/**
 * ClassName: FindCenter <br/>
 * Description: <br/>
 * date: 2022/5/29 20:34<br/>
 *
 * @author Hesion<br />
 * @version
 * @since JDK 1.8
 */

import java.util.HashMap;

/**
 * 1791. 找出星型图的中心节点
 * @author: hesion
 * @create: 2022-05-29 20:34
 **/
public class FindCenter {
    public int findCenter(int[][] edges) {
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int[] edge : edges) {
            map.put(edge[0],map.getOrDefault(edge[0],0)+1);
            map.put(edge[1],map.getOrDefault(edge[1],0)+1);
        }

        for (Integer node : map.keySet()) {
            if(map.getOrDefault(node,0)==edges.length-1){
                return node;
            }
        }

        return -1;
    }
}
